package com.stock.publiclib.network;

import android.content.Context;

import com.android.volley.RequestQueue;
import com.android.volley.toolbox.Volley;
import com.squareup.okhttp.OkHttpClient;

import java.util.Map;

import javax.net.ssl.SSLSocketFactory;

/**
 * ---------------------------------------------------
 * Description: volley的封装类,用来管理网络访问队列
 * Author: ljgsonx
 * Belong to: com.baiwang.bwbaselib.network
 * Time: 2016/1/15 15:21
 * ---------------------------------------------------
 */
public class NetWorkCenter {

    private static RequestQueue mRequestQueue;

    public static RequestQueue getQueue(Context context) {

        return getQueue(context, null);
    }

    public static RequestQueue getQueue(Context context,Map<String, SSLSocketFactory> factoryMap) {

        return getQueue(context, factoryMap, null);
    }

    public static RequestQueue getQueue(Context context,Map<String, SSLSocketFactory> factoryMap,OkHttpClient okHttpClient){
        if(null == mRequestQueue){
            if(null != factoryMap){
                if(null != okHttpClient){
                    mRequestQueue = Volley.newRequestQueue(context, new SelfSignSslOkHttpStack(okHttpClient,factoryMap));
                }else{
                    mRequestQueue = Volley.newRequestQueue(context, new SelfSignSslOkHttpStack(factoryMap));
                }
            }else{
                mRequestQueue = Volley.newRequestQueue(context, new OkHttpStackByHttpUrlConnection());
            }
        }
        return mRequestQueue;
    }
}
